
package com.example.service.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.entity.Score;
import com.example.mapper.ScoreMapper;
import com.example.service.ScoreService;
import com.example.vo.ScoreQueryVO;
import com.example.vo.ScoreResultVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import lombok.extern.slf4j.Slf4j;

@Slf4j // 专业的日志系统，日志可以分级别（info、debug、warn、error），可灵活配置输出到文件、控制台、远程等
@Service
public class ScoreServiceImpl extends ServiceImpl<ScoreMapper, Score> implements ScoreService {

    @Autowired
    private ScoreMapper scoreMapper;

    @Override
    public boolean saveScore(Score score) {
        log.info("info:我是{}注解，我是专业的日志输出系统", "@Slf4j");
        log.info("info:保存成绩: {}", score);
        boolean result = this.save(score);
        if (result) {
            log.info("info:成绩保存成功，ID={}", score.getId());
        } else {
            log.error("error:成绩保存失败: {}", score);
        }
        return result;
    }

    @Override
    public boolean updateScore(Score score) {
        log.info("info:我是{}注解，我是专业的日志输出系统", "@Slf4j");
        log.info("info:更新成绩: {}", score);
        boolean result = this.updateById(score);
        if (result) {
            log.info("info:成绩更新成功，ID={}", score.getId());
        } else {
            log.error("error:成绩更新失败: {}", score);
        }
        return result;
    }

    @Override
    public boolean deleteScore(Long id) {
        log.info("info:我是{}注解，我是专业的日志输出系统", "@Slf4j");
        log.warn("warn:删除成绩，ID={}", id);
        boolean result = this.removeById(id);
        if (result) {
            log.info("info:成绩删除成功，ID={}", id);
        } else {
            log.error("error:成绩删除失败，ID={}", id);
        }
        return result;
    }

    @Override
    public Score getScoreById(Long id) {
        log.info("info:我是{}注解，我是专业的日志输出系统", "@Slf4j");
        log.debug("debug:查询成绩，ID={}", id);
        return this.getById(id);
    }

    @Override
    public IPage<ScoreResultVO> queryScores(Page<?> page, ScoreQueryVO queryVO) {
        // 复杂联表分页查询，需自定义SQL，见src/main/resources/mapper/ScoreMapper.xml
        return scoreMapper.queryScores(page, queryVO);
    }
}
